unit UsuarioPerfilSearchFr;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, Buttons, StdCtrls, DBCtrls, MainSearchFr;

type

  { TUsuarioPerfilSearchFrame }

  TUsuarioPerfilSearchFrame = class(TMainSearchFrame)
    Buscar: TBitBtn;
    id_perfil: TDBLookupComboBox;
    id_pessoa: TEdit;
    nome_pessoa: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure BuscarClick(Sender: TObject);
    procedure LocalizarButtonClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

implementation

uses Initializator, UsuarioPerfilDM, QueryConditions, MainFr;

{ TUsuarioPerfilSearchFrame }

procedure TUsuarioPerfilSearchFrame.BuscarClick(Sender: TObject);
begin
  TheControl.ShowForeignFrame(TMainFrame(UsuarioSearchFrame));
end;

procedure TUsuarioPerfilSearchFrame.LocalizarButtonClick(Sender: TObject);
var
  condicoes: TQueryConditions;
begin
  condicoes := TQueryConditions.Create(CON_AND);
  Condicoes.AddJoinField('up.id_perfil', 'pf.id_perfil');
  Condicoes.AddJoinField('up.id_usuario', 'u.id_usuario');
  Condicoes.AddJoinField('u.id_usuario', 'p.id_pessoa');
  condicoes.Add('up.id_usuario', id_pessoa.Text);
  if id_perfil.Text <> '' then begin;
  condicoes.Add('up.id_perfil', id_perfil.KeyValue);
  end;
  condicoes.AddText('p.id_pessoa', id_pessoa.Text);
  condicoes.AddText('p.nome_pessoa', nome_pessoa.Text);
  UsuarioPerfilData.Search(condicoes, 'usuario as u, pessoa as p, usuario_perfil as up, perfil as pf');
end;

initialization
  {$I usuarioperfilsearchfr.lrs}

end.

